package com.wht.controller;

import com.wht.service.DeleteMusicService;
import com.wht.service.DeleteMusicServiceImpl;
import com.wht.service.DeleteMusicSingerService;
import com.wht.service.DeleteMusicSingerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wanghaotian
 * time:2022/11/28,0028 19:59
 * description:
 */

@WebServlet("/DeleteMusicController")
public class DeleteMusicController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String mid = req.getParameter("mid");
        DeleteMusicService deleteMusicService = new DeleteMusicServiceImpl();
        DeleteMusicSingerService deleteMusicSingerService = new DeleteMusicSingerServiceImpl();
        int number = deleteMusicService.deleteMusic(Integer.parseInt(mid));
        if(number>0){
            deleteMusicSingerService.deleteMusicSinger(mid);
        }
        resp.sendRedirect("/FindAllMusicController");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}